import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import request from 'utils/request';
import { CPAAS_FILE, CPAAS_PLATFORM } from 'utils/config';
import { isTenantRoleLevel } from 'utils/utils';
var isSiteFlag = !isTenantRoleLevel();

function apiSource(params) {
  return isSiteFlag ? "".concat(CPAAS_FILE, "/v2/storage-configs") : "".concat(CPAAS_FILE, "/v2/").concat(params.tenantId, "/storage-configs");
}
/**
 * 查询默认文件存储配置
 * @param {Object} params - 查询参数
 * @param {String} params.page - 页码
 * @param {String} params.size - 页数
 */


export function fetchDefaultStorage(_x) {
  return _fetchDefaultStorage.apply(this, arguments);
}
/**
 * 查询文件存储配置
 * @param {Object} params - 查询参数
 * @param {String} params.page - 页码
 * @param {String} params.size - 页数
 */

function _fetchDefaultStorage() {
  _fetchDefaultStorage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(apiSource(params)), {
              method: 'GET',
              query: {
                tenantId: params.tenantId
              }
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchDefaultStorage.apply(this, arguments);
}

export function fetchStorage(_x2) {
  return _fetchStorage.apply(this, arguments);
}
/**
 * 查询文件存储配置
 * @param {Object} params - 查询参数
 * @param {String} params.page - 页码
 * @param {String} params.size - 页数
 */

function _fetchStorage() {
  _fetchStorage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(apiSource(params), "/").concat(params.storageType), {
              method: 'GET',
              query: {
                tenantId: params.tenantId
              }
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _fetchStorage.apply(this, arguments);
}

export function updateStorage(_x3) {
  return _updateStorage.apply(this, arguments);
}
/**
 * 删除文件存储配置
 * @param {Object} params - 查询参数
 * @param {String} params.page - 页码
 * @param {String} params.size - 页数
 */

function _updateStorage() {
  _updateStorage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(apiSource(params)), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _updateStorage.apply(this, arguments);
}

export function deleteStorage(_x4) {
  return _deleteStorage.apply(this, arguments);
}
/**
 * 查询文件存储配置权限控制父子值集
 * @param {Object} params - 查询参数
 */

function _deleteStorage() {
  _deleteStorage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(apiSource(params)), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _deleteStorage.apply(this, arguments);
}

export function queryLdpTree(_x5) {
  return _queryLdpTree.apply(this, arguments);
}

function _queryLdpTree() {
  _queryLdpTree = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/lovs/value/tree"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _queryLdpTree.apply(this, arguments);
}